package com.wars2donline.client.graphics;

import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.wars2donline.client.actor.HeroActor;
import com.wars2donline.client.data.HeroData;
import com.wars2donline.client.json.JSONParser;

public class GameStage extends Stage {

	HeroActor mHero = null;
	
	public GameStage(float width, float height, boolean stretch) {
		super(width, height, stretch);
		
		HeroData data = new HeroData();
		data.id = 1;
		
		new JSONParser().getHeroActor(1, data);
		
		mHero = new HeroActor(data);
		
		mHero.x = 100;
		mHero.y = 100;
		
		addActor(mHero);
	}
	
	
	@Override
	public void draw() {
		super.draw();
		
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		batch.begin();
		
		List<Actor> actors = getActors();
		
		for (Actor actor : actors) {
			actor.draw(batch, 1.0f);
		}
		
		batch.end();
	}
	
	@Override
	public void act(float delta) {
		super.act(delta);
		
		List<Actor> actors = getActors();
		
		for (Actor actor : actors) {
			actor.act(delta);
		}
		
		if (Gdx.input.isKeyPressed(Keys.RIGHT)) {
			mHero.walkRight(delta);
		} else if (Gdx.input.isKeyPressed(Keys.LEFT)) {
			mHero.walkLeft(delta); 
		} else {
			mHero.setIdleState();
		}
	}
}
